#include "modbus_register.h"

#include "ice_cream_process.h"


uint16_t modbus_topping_get(uint16_t address) {

    ice_cream_process_data_t *process_data=  ice_icream_process_data_get();
    int toppingid =    (address-REG_TOPPING1_POS_BASE)/(REG_TOPPING1_REMAIN_COUNT-REG_TOPPING1_POS_BASE);
    int toppingvalueid =  (address-REG_TOPPING1_POS_BASE)%(REG_TOPPING1_REMAIN_COUNT-REG_TOPPING1_POS_BASE);
    uint16_t *topping_param= (uint16_t*)&process_data->config.toppings[toppingid].add_pos;
    switch (toppingvalueid+REG_TOPPING1_POS_BASE)
    {
     case REG_JAM1_TIME_BASE:
         return topping_param[toppingvalueid]/1000;
     case REG_JAM1_TIME_BASE+1:
        return topping_param[toppingvalueid]/1000;

    }
    return topping_param[toppingvalueid];
}


void modbus_topping_set(uint16_t address, uint16_t value) {


    ice_cream_process_data_t *process_data=  ice_icream_process_data_get();
    int toppingid =    (address-REG_TOPPING1_POS_BASE)/(REG_TOPPING1_REMAIN_COUNT-REG_TOPPING1_POS_BASE);
    int toppingvalueid =  (address-REG_TOPPING1_POS_BASE)%(REG_TOPPING1_REMAIN_COUNT-REG_TOPPING1_POS_BASE);
    uint16_t *topping_param= (uint16_t*)&process_data->config.toppings[toppingid].add_pos;
    topping_param[toppingvalueid]=value;
    switch (toppingvalueid+REG_TOPPING1_POS_BASE)
    {
     case REG_JAM1_TIME_BASE:
          topping_param[toppingvalueid]=value*1000;
     case REG_JAM1_TIME_BASE+1:
         topping_param[toppingvalueid]=value*1000;

    }

}
